package com.oh.activity;

import com.oh.view.DialogManager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * 
 * 
 * 用户登录界面
 * 
 * @author Alex.Lu
 * 
 */
public class LoginActivity extends Activity implements OnClickListener {
	/** Called when the activity is first created. */

	private static final int MENU_ITEM_SETUP = 0x1;

	private EditText mUserNameET;
	private EditText mPasswordET;

	private Button mLoginBT;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_login);

		mUserNameET = (EditText) findViewById(R.id.username);
		mPasswordET = (EditText) findViewById(R.id.userpassword);

		mLoginBT = (Button) findViewById(R.id.login);
		mLoginBT.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		menu.add(0, MENU_ITEM_SETUP, 0, this.getResources().getString(R.string.btn_setup));
		return true;
	}

	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case MENU_ITEM_SETUP:
			DialogManager.getInstance().createLoginAdmin(this, null);
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int v_id = v.getId();
		switch (v_id) {
		case R.id.login:

			String username = mUserNameET.getText().toString();
			String password = mPasswordET.getText().toString();

			Intent intent = new Intent();
			intent.setClass(this, MainActivity.class);
			startActivity(intent);

			break;

		default:
			break;
		}
	}

}